'''贪心算法
如何找出覆盖全美50个州的最小广播台集合
'''

states_needed = set(["mt", "wa", "or", "id", "nv", "ut",  #要被覆盖的州
"ca", "az"])

'散列表表示每个广播站能广播的州'
stations = {}
stations["kone"] = set(["id", "nv", "ut"])
stations["ktwo"] = set(["wa", "id", "mt"])
stations["kthree"] = set(["or", "nv", "ca"])
stations["kfour"] = set(["nv", "ut"])
stations["kfive"] = set(["ca", "az"])

final_stations = set()  #存放最终选择的州

def greed_algorithms():
    global states_needed
    while states_needed:
        best_station=None
        states_covered = set()  # 已经被覆盖的州
        for station,states in stations.items():
            coverd=states_needed&states
            if len(coverd)>len(states_covered):
                best_station=station
                states_covered=coverd
        states_needed-=states_covered
        final_stations.add(best_station)

greed_algorithms()
print(final_stations)